package com.caikun.service_management.controller;

import com.caikun.model.common.Result;
import com.caikun.model.dto.PackageDTO;
import com.caikun.model.dto.PackageUpdateDTO;
import com.caikun.service_management.service.PackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/package")
@Slf4j
@Tag(name = "套餐管理")
public class PackageController {
    @Autowired
    private PackageService packageService;

    /**
     * 新增套餐及套餐详情
     * @param packageDTO
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "新增套餐")
    public Result<Map<String, Object>> addPackage(@RequestBody PackageDTO packageDTO){
        return Result.success(packageService.add(packageDTO));
    }

    /**
     * 删除套餐及套餐详情
     * @param packageId
     * @return
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除套餐")
    public Result<Boolean> deletePackage(Integer packageId){
        return Result.success(packageService.delete(packageId));
    }

    /**
     * 更新套餐及套餐详情
     * @param packageUpdateDTO
     * @return
     */
    @PutMapping("/update")
    @Operation(summary = "更新套餐")
    public Result<Map<String, Object>> updatePackage(@RequestBody PackageUpdateDTO packageUpdateDTO){
        return Result.success(packageService.update(packageUpdateDTO));
    }

}
